package com.powernode.util;

import com.powernode.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Set;

/**
 * @Description: 认证授权工具类
 * @Author: Tong Ziyu
 * @Date: 2025/1/5 00:00
 */
public class AuthUtil {

    /**
     * 工具方法,获取当前登录用户
     * @return
     */
    public static SecurityUser getLoginUser(){
        return (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 工具方法,获取当前登录用户的id
     * @return
     */
    public static Long getLoginUserId(){
        return getLoginUser().getUserId();
    }

    /**
     * 工具方法,获取当前登录用户的权限
     * @return
     */
    public static Set<String> getLoginUserPerms(){
        return getLoginUser().getPerms();
    }
}
